package com.wangjiyuan.giftshuo.ui.activity.listtop;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.CardView;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.wangjiyuan.giftshuo.R;
import com.wangjiyuan.giftshuo.base.BaseActivity;
import com.wangjiyuan.giftshuo.bean.listtopbean.everydaybean.EveryDayBean;
import com.wangjiyuan.giftshuo.bean.listtopbean.maybelikebean.MayBeLikeBean;
import com.wangjiyuan.giftshuo.ui.fragment.listtop.adapter.DetailsViewPagerAdapter;
import com.wangjiyuan.giftshuo.ui.fragment.listtop.other.CommentFragment;
import com.wangjiyuan.giftshuo.ui.fragment.listtop.other.DetailsFragment;
import com.wangjiyuan.giftshuo.ui.fragment.listtop.other.SingleProductFragment;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class DetailsItemActivity extends BaseActivity implements View.OnClickListener {

    private Context mContext = this;
    private ImageView img_details_back, img_details_collect, img_details_share,
            img_details_talk;
    private TabLayout tab_details_title;
    private CardView cv_details_taoBao;

    //需要更改Path路径的Id
    private int id;

    private ViewPager vp_details_main;
    private List<Fragment> mFragmentList = new ArrayList<>();
    private DetailsViewPagerAdapter detailsViewPagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_details_item);

        initData();
        initView();
    }

    private void initData() {
        Intent intent = getIntent();
        id = (int) intent.getSerializableExtra("itemId");
        Bundle bundle = new Bundle();
        bundle.putSerializable("itemId", id);
        DetailsFragment detailsFragment = new DetailsFragment();
        SingleProductFragment singleProductFragment = new SingleProductFragment();
        CommentFragment commentFragment = new CommentFragment();

        singleProductFragment.setArguments(bundle);
        detailsFragment.setArguments(bundle);
        commentFragment.setArguments(bundle);

        mFragmentList.add(singleProductFragment);
        mFragmentList.add(detailsFragment);
        mFragmentList.add(commentFragment);
    }

    private void initView() {
        img_details_back = (ImageView) findViewById(R.id.img_details_back);
        img_details_collect = (ImageView) findViewById(R.id.img_details_collect);
        img_details_share = (ImageView) findViewById(R.id.img_details_share);
        tab_details_title = (TabLayout) findViewById(R.id.tab_details_title);
        cv_details_taoBao = (CardView) findViewById(R.id.cv_details_taoBao);
        vp_details_main = (ViewPager) findViewById(R.id.vp_details_main);
        img_details_talk = (ImageView) findViewById(R.id.img_details_talk);

        detailsViewPagerAdapter = new DetailsViewPagerAdapter(
                getSupportFragmentManager(), mFragmentList);
        vp_details_main.setOffscreenPageLimit(2);
        vp_details_main.setAdapter(detailsViewPagerAdapter);

        tab_details_title.setupWithViewPager(vp_details_main);

        img_details_back.setOnClickListener(this);
        img_details_collect.setOnClickListener(this);
        img_details_share.setOnClickListener(this);
        cv_details_taoBao.setOnClickListener(this);
        img_details_talk.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.img_details_back:
                finish();
                break;
            case R.id.img_details_collect:
                Toast.makeText(mContext, "collection", Toast.LENGTH_SHORT).show();
                break;
            case R.id.img_details_share:
                Toast.makeText(mContext, "share", Toast.LENGTH_SHORT).show();
                break;
            case R.id.cv_details_taoBao:
                intent.setClass(this, TaoBaoBuyActivity.class);
                intent.putExtra("itemId", id);
                startActivity(intent);
                break;
            case R.id.img_details_talk:
                Toast.makeText(mContext, "写评论", Toast.LENGTH_SHORT).show();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
